var dictDataAddCtrl  = new XFApp.client();

XFApp.client.prototype.dictDataAdd = {
		successCode : 10000,	
		urlItems : {
			saveDictDataURL: basePath+"/dict/saveDictData",
		},	
		
		saveDictType : function (){	
			
			var params = {
				dictName : $("#dictName").val(),
				systemDictName : $("#systemDictName").val(),	
				dictCode : $("#dictCode").val(),				
				dictType : $("#dictType").attr("data-id"),
				isRemoved:0,
			};
			
			$.ajax ({
				url :_this.urlItems.saveDictDataURL,
				data : params,
				dataType : "json",
				type : 'post',
				success : function(data) {
					if(data.code == _this.successCode){						
						window.webDialogUtil.alert("提示",data.msg);	
						$('#addForm')[0].reset(); 
		        	}else{
		        		
		        		window.webDialogUtil.alert("提示",data.msg);		        		
		        	}
				}
			});			
		},		
		
		initSelect : function (){
			
			$("#dictType").bsSuggest({
				idField: "dicttypeid",  
				keyField: "dicttypename",
				effectiveFields :["dicttypeid","dicttypename"],
				effectiveFieldsAlias:{dicttypeid:"编码",dicttypename:"名称"},
		        data: {
		           'value':dictTypes
		        }
		   });
			
		},
		
		event : function(){
			_this = this;			
			$("#submitBtn").on("click",function(){
				if($("#addForm").validate().form()){
					dictDataAddCtrl.dictDataAdd.saveDictType();
				}
			});
			//表单验证
			_this.formValidate();	
		},
		
		formValidate : function(){
			$("#addForm").validate({
		        rules: {
		        	dictName: "required",
		        	dictCode: "required",
		        	dictType: "required"
				  },
				 messages: {
					 dictName: "请填写简称",
					 dictCode: "请填写编码",
					 dictType: "请选择所属类型"
			         }
		    });
			$("#addForm").validate();
		},
};


$(function(){
	dictDataAddCtrl.dictDataAdd.event();
	dictDataAddCtrl.dictDataAdd.initSelect();
});